// 约定一个通用的key
const INFO_KEY = 'pink_shooping'
const SEARCHLIST = 'searchList'

// 获取个人信息
export const getInfo = () => {
  const defaultObj = { token: '', userId: '' }
  const result = localStorage.getItem(INFO_KEY)
  return result ? JSON.parse(result) : defaultObj
}

// 设置个人信息
export const setInfo = (data) => {
  localStorage.setItem(INFO_KEY, JSON.stringify(data))
}
// 删除个人信息
export const removeInfo = () => {
  localStorage.removeItem(INFO_KEY)
}

// 获取搜索历史
export const getSearchList = () => {
  const defaultObj = []
  const list = localStorage.getItem(SEARCHLIST)
  return list ? JSON.parse(list) : defaultObj
}
// 设置搜索历史
export const setSearchList = (list) => {
  localStorage.setItem(SEARCHLIST, JSON.stringify(list))
}
// 删除搜索历史
export const removeSearchList = () => {
  localStorage.removeItem(SEARCHLIST)
}
